//
//  UITableView+Cell.m
//  UniversalApp
//
//  Created by 郭颢源 on 2020/8/19.
//  Copyright © 2020 bianruifeng. All rights reserved.
//

#import "UITableView+Cell.h"

@implementation UITableView (cell)

- (void)registerNib:(nullable Class)cellClass
{
    NSString *name= NSStringFromClass(cellClass);
    UINib *nib=[UINib nibWithNibName:name bundle:nil];
    if(nib==nil){
        NSLog(@"CellView：从xib创建视图失败，当前类是：%@",name);
    }
    [self registerNib:nib forCellReuseIdentifier:name];
}

- (void)registerClass:(nullable Class)cellClass
{
    NSString *name= NSStringFromClass(cellClass);
    [self registerClass:cellClass forCellReuseIdentifier:name];
}

- (void)registerHeaderFooterNib:(nullable Class)cellClass
{
    NSString *name= NSStringFromClass(cellClass);
    UINib *nib=[UINib nibWithNibName:name bundle:nil];
    if(nib==nil){
        NSLog(@"HeaderFooterView：从xib创建视图失败，当前类是：%@",name);
    }
    [self registerNib:nib forHeaderFooterViewReuseIdentifier:name];
}

- (void)registerHeaderFooterClass:(nullable Class)cellClass
{
    NSString *name= NSStringFromClass(cellClass);
    [self registerClass:cellClass forHeaderFooterViewReuseIdentifier:name];
}

-(__kindof UITableViewCell *)dequeueReusableCell:(nullable Class)cellClass
{
    NSString *name= NSStringFromClass(cellClass);
    return [self dequeueReusableCellWithIdentifier:name];
}

-(__kindof UITableViewHeaderFooterView *)dequeueReusableHeaderFooterView:(nullable Class)cellClass
{
    NSString *name= NSStringFromClass(cellClass);
    return [self dequeueReusableHeaderFooterViewWithIdentifier:name];
}

-(__kindof UITableViewCell *)cellClass:(nullable Class)cellClass
{
    UITableViewCell * cell = [self dequeueReusableCell:cellClass];
    if (cell) {
        return cell;
    }
    [self registerClass:cellClass];
    return [self dequeueReusableCell:cellClass];
}

-(__kindof UITableViewCell *)cellNib:(nullable Class)cellClass
{
    UITableViewCell * cell = [self dequeueReusableCell:cellClass];
    if (cell) {
        return cell;
    }
    [self registerNib:cellClass];
    return [self dequeueReusableCell:cellClass];
}

-(__kindof UITableViewHeaderFooterView *)headerFooterViewWithClass:(nullable Class)cellClass
{
    UITableViewHeaderFooterView *HeaderFooterView = [self dequeueReusableHeaderFooterView:cellClass];
    if (HeaderFooterView) {
        return HeaderFooterView;
    }
    [self registerHeaderFooterClass:cellClass];
    return [self dequeueReusableHeaderFooterView:cellClass];
}

-(__kindof UITableViewHeaderFooterView *)headerFooterViewWithNib:(nullable Class)cellClass
{
    UITableViewHeaderFooterView *HeaderFooterView = [self dequeueReusableHeaderFooterView:cellClass];
    if (HeaderFooterView) {
        return HeaderFooterView;
    }
    [self registerHeaderFooterNib:cellClass];
    return [self dequeueReusableHeaderFooterView:cellClass];
}
//        static NSString *CellIdentifier = @"UITableViewCell";
//        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
//        if (!cell) {
//            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
//        }
@end
